from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import config


db = SQLAlchemy()


def create_app():
    app = Flask(__name__)
    app.config.from_object(config)

    # 注册 user 路由
    from .user import user_blueprint
    app.register_blueprint(blueprint=user_blueprint, url_prefix="/user")
    # 注册 course 路由
    from .course import course_blueprint
    app.register_blueprint(blueprint=course_blueprint, url_prefix="/course")
    # 注册 news 路由
    from .news import news_blueprint
    app.register_blueprint(blueprint=news_blueprint, url_prefix="/news")
    # 注册 homework 路由
    from .homework import homework_blueprint
    app.register_blueprint(blueprint=homework_blueprint, url_prefix="/homework")
    # 注册 exam 路由
    from .exam import exam_blueprint
    app.register_blueprint(blueprint=exam_blueprint, url_prefix="/exam")
    # 注册 system 路由
    from .system import system_blueprint
    app.register_blueprint(blueprint=system_blueprint, url_prefix="/system")
    # 注册 question 路由
    from .question import question_blueprint
    app.register_blueprint(blueprint=question_blueprint, url_prefix="/question")
    # 注册 paper 路由
    from .paper import paper_blueprint
    app.register_blueprint(blueprint=paper_blueprint, url_prefix="/paper")

    db.init_app(app)

    return app
